﻿using Share.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Share.APIs;

public class PayEnt : IcbcApiRequest
{
    internal override string Url => "api/mybank/enterprise/pay/payent/V2";
    [JsonPropertyName("trans_code")] public string TransCode => "PAYENT";
    [JsonPropertyName("tran_date")] public string TranDate { get; set; } = DateTime.Today.ToString("yyyyMMdd");
    [JsonPropertyName("tran_time")] public string TranTime { get; set; } = DateTime.Now.ToString("HHmmssfff");
    [JsonPropertyName("language")] public string? Language { get; set; } = "zh_CN";
    [JsonPropertyName("f_seq_no")] public string FSeqNo { get; set; } = UtilitiesService.GetFSeqNo();
    [JsonPropertyName("zip_flag")] public string? ZipFlag { get; set; } = string.Empty;
    [JsonPropertyName("zip")] public string? Zip { get; set; } = string.Empty;
    [JsonPropertyName("settle_mode")] public string SettleMode { get; set; } = "0"; // 入账方式：0：逐笔记账；2：并笔记账
    [JsonPropertyName("instr_count")] public int InstrCount => Rd.Count; // 根据 Rd 的个数自动生成
    [JsonPropertyName("total_amount")] public decimal TotalAmount => Rd.Sum(x => x.Amount);
    [JsonPropertyName("package_name")] public string? PackageName { get; set; } = string.Empty;
    [JsonPropertyName("rd")] public List<PayEntRequestRd> Rd { get; set; } = [];


}

public class PayEntRequestRd
{
    [JsonPropertyName("uni_busi_id")] public string UniBusiId { get; set; } = string.Empty;
    [JsonPropertyName("i_seq_no")] public string ISeqNo { get; set; } = UtilitiesService.GetFSeqNo();
    [JsonPropertyName("schedule_date")] public string? ScheduleDate { get; set; } = string.Empty;
    [JsonPropertyName("pay_type")] public string PayType { get; set; } = "1";// 记账处理方式：1：加急；2：普通；3：跨行快汇
    [JsonPropertyName("payer_account")] public string? PayerAccount { get; set; } = string.Empty;
    [JsonPropertyName("payer_cnname")] public string? PayerCnname { get; set; } = string.Empty;
    [JsonPropertyName("payer_enname")] public string? PayerEnname { get; set; } = string.Empty;
    [JsonPropertyName("manager_card_no")] public string? ManagerCardNo { get; set; } = string.Empty;
    [JsonPropertyName("manager_card_name")] public string? ManagerCardName { get; set; } = string.Empty;
    [JsonPropertyName("payee_account")] public string PayeeAccount { get; set; } = string.Empty;
    [JsonPropertyName("payee_cnname")] public string? PayeeCnname { get; set; } = string.Empty;
    [JsonPropertyName("payee_enname")] public string? PayeeEnname { get; set; } = string.Empty;
    [JsonPropertyName("io_flag")] public string IoFlag { get; set; } = "1"; // 转到： 1=工行 2=他行
    [JsonPropertyName("same_city_flag")] public string? SameCityFlag { get; set; } = string.Empty;
    [JsonPropertyName("payee_type")] public string? PayeeType { get; set; } = string.Empty;
    [JsonPropertyName("payee_city")] public string? PayeeCity { get; set; } = string.Empty;
    [JsonPropertyName("payee_bank_no")] public string? PayeeBankNo { get; set; } = string.Empty;
    [JsonPropertyName("payee_bank_name")] public string? PayeeBankName { get; set; } = string.Empty;
    [JsonPropertyName("currency")] public string Currency { get; set; } = "CNY";
    [JsonPropertyName("amount")] public decimal Amount { get; set; }
    [JsonPropertyName("purpose_code")] public string? PurposeCode { get; set; } = string.Empty;
    [JsonPropertyName("purpose")] public string? Purpose { get; set; } = string.Empty;
    [JsonPropertyName("summary")] public string? Summary { get; set; } = string.Empty;
    [JsonPropertyName("summary_en")] public string? SummaryEn { get; set; } = string.Empty;
    [JsonPropertyName("postscript")] public string? Postscript { get; set; } = string.Empty;
    [JsonPropertyName("ref_no")] public string? RefNo { get; set; } = string.Empty;
    [JsonPropertyName("related_ref_no")] public string? RelatedRefNo { get; set; } = string.Empty;
    [JsonPropertyName("erp_serial_no")] public string? ErpSerialNo { get; set; } = string.Empty;
    [JsonPropertyName("erp_check_no")] public string? ErpCheckNo { get; set; } = string.Empty;
    [JsonPropertyName("busi_code")] public string? BusiCode { get; set; } = string.Empty;
    [JsonPropertyName("ori_voucher_type")] public string? OriVoucherType { get; set; } = string.Empty;
    [JsonPropertyName("ori_voucher_no")] public string? OriVoucherNo { get; set; } = string.Empty;
    [JsonPropertyName("ori_voucher_name")] public string? OriVoucherName { get; set; } = string.Empty;
    [JsonPropertyName("pre_approval_no")] public string? PreApprovalNo { get; set; } = string.Empty;
    [JsonPropertyName("regulation_purpose_code")] public string? RegulationPurposeCode { get; set; } = string.Empty;
}


public class PayEntResponse:IcbcApiResponse
{    
    [JsonPropertyName("serial_no")] public string? SerialNo { get; set; } = string.Empty;
    [JsonPropertyName("result")] public string? Result { get; set; } = string.Empty;
}